﻿using System;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Phone.Shell;
using Renren.Models;
using Renren.Services;
using System.Windows;
using Microsoft.Phone.Controls;
using Renren.Common;

namespace Renren.Controls
{
    public partial class FriendStreamBox : UserControl
    {
        public event EventHandler<FriendTapEventArgs> FriendTap;

        public FriendStreamBox()
        {
            InitializeComponent();
            DataContext = App.ViewModel;
            if (App.ViewModel.FriendList.Count == 0)
            {
                FriendService.GetFriends(App.ViewModel.FriendList, RequestType.GetInit);
            }
            this.StreamBox.LoadHead += (s, e) => FriendService.GetFriends(App.ViewModel.FriendList, RequestType.GetInit, e.Callback);
            this.StreamBox.LoadTail += (s, e) => FriendService.GetFriends(App.ViewModel.FriendList, RequestType.GetMore, e.Callback);
        }

        private void Friend_Tap(object sender, GestureEventArgs e)
        {
            FriendTap(this, new FriendTapEventArgs(this.StreamBox.SelectedItem as FriendModel));
            //long id = (this.StreamBox.SelectedItem as FriendModel).UserId;
            //PhoneApplicationService.Current.State["UserPage"] = id;
            //(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/UserPage.xaml", UriKind.Relative));
        }
    }
}
